using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace LS.GameKit
{
    [Serializable]
    public class EnumContainer
    {
        public string name;
        public List<EnumContent> contents = new List<EnumContent>();
        public int Count => contents.Count;

        public EnumContent this[int index]
        {
            get
            {
                if(index >= 0 && index < contents.Count)
                    return contents[index];
                else 
                    return null;
            }
        }
        
        public EnumContent this[string key]
        {
            get
            {
                return contents.First(c=>c.name == key);
            }
        }
        
        public string GetName(int value)
        {
            return contents.First(c=>c.value == value)?.name ?? null;
        }
        
        public int? GetValue(string name)
        {
            return contents.First(c=>c.name == name)?.value ?? null;
        }
        
        public bool Contains(string name)
        {
            return contents.First(c=>c.name == name) != null;
        }
        
        public bool Contains(int value)
        {
            return contents.First(c=>c.value == value) != null;
        }
    }
}
